﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 药品信息管理
{
    public partial class YP_CKDCX_MX : Form
    {
        public YP_CKDCX_MX()
        {
            InitializeComponent();
        }
        public string ckdh;
        private void buttonItem2_Click(object sender, EventArgs e)
        {
            db db1 = new db();
            db1.DataToExcel(dataGridViewX1);
        }

        private void YP_CKDCX_MX_Load(object sender, EventArgs e)
        {
            db db1 = new db();
            DataTable dt = db1.sqldt(@"SELECT C0.CKDH 出库单号,convert(datetime,C0.RQ-2) 制单日期,KS.MC 出库科室,CR.MC 类型,C0.SHRY 审核人员,
                           C0.SHRY 记账人员,C0.LRRY 录入人员,(select NAME from zd_ry where UID = C0.LYR) 领用人, 
                            HJ.JJJE 进价金额, HJ.LSJE 零售金额, HJ.YPCOUNT 药品种量
                           FROM YK_CKD0 C0
                                LEFT JOIN YK_CRLX CR ON C0.CKLX = CR.BM
                                LEFT JOIN ZD_KS KS ON C0.KSBM=KS.BM
                                LEFT JOIN (SELECT CKDH, SUM(CBJE) AS JJJE, SUM(JE) AS LSJE,COUNT(*) AS YPCOUNT FROM YK_CKD1 GROUP BY CKDH) HJ  ON C0.CKDH = HJ.CKDH 
                                WHERE C0.CKLX = CR.BM and c0.ckdh = " + ckdh + " AND  C0.KSBM=KS.BM");

            textBoxX1.Text = ckdh;
            try { textBoxX2.Text = dt.Rows[0]["出库科室"].ToString(); }
            catch { }
            try { textBoxX3.Text = dt.Rows[0]["领用人"].ToString(); }
            catch { }
            try { textBoxX4.Text = dt.Rows[0]["录入人员"].ToString(); }
            catch { }
            try { dateTimePicker1.Text = dt.Rows[0]["制单日期"].ToString(); }
            catch { }
            try { textBoxX5.Text = dt.Rows[0]["审核人员"].ToString(); }
            catch { }
            try { textBoxX6.Text = dt.Rows[0]["记账人员"].ToString(); }
            catch { }
            try { textBoxX7.Text = dt.Rows[0]["出库科室"].ToString(); }
            catch { }
            try { textBoxItem1.Text = dt.Rows[0]["药品种量"].ToString(); }
            catch { }
            try { textBoxItem3.Text = dt.Rows[0]["进价金额"].ToString(); }
            catch { }
            try { textBoxItem4.Text = dt.Rows[0]["零售金额"].ToString(); }
            catch { }


            dataGridViewX1.DataSource = db1.sqldt(@"SELECT  c1.YPBM 药品编码,YP.MC 药品名称,YP.GG 药品规格,c1.NCSL 拟出数量, c1.SL 数量, 
                                                    c1.DJ 单价, c1.JE 金额,c1.PJ 批价, c1.PJJE 批价金额 FROM YK_CKD1 C1
                                                    LEFT JOIN YK_RKD1 R1 ON C1.AUTORKID = R1.AUTORKID
                                                    LEFT JOIN YK_RKD0 R0 ON R1.RKDH = R0.RKDH,
                                                    ZD_YP YP
                                                    WHERE C1.YPBM=YP.BM and C1.ckdh=" + ckdh);
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {
            dgVprint1.Print(dataGridViewX1,true);
        }
    }
}